package com.zjc.app.api.sdk.dto.result;


import com.zjc.app.api.sdk.Constants.Constants;
import com.zjc.app.api.sdk.utils.StringUtils;
import lombok.Data;

import java.util.Date;
import java.util.Map;

@Data
public class ProductPropertyWithValueDTO {
    private String identifier;
    private String name;
    private String group;
    private DataType dataType;
    private Date time;
    private String value;
    private String valueName;

    public void buildValueName() {
        if (dataType != null) {
            Map<String, String> definition = dataType.getDefinition();
            if (!(definition==null||definition.isEmpty())) {
                valueName = definition.get(value);
            }
        }
    }

    /**
     * 拼接属性单位
     */
    public void addUnit() {
        if (dataType != null) {
            Map<String, String> definition = dataType.getDefinition();
            if (!(definition==null||definition.isEmpty())) {
                String unit = definition.get(Constants.UNIT);
                if (valueName != null && !StringUtils.isEmpty(unit)) {
                    valueName = valueName + " " + definition.get(Constants.UNIT);
                }
                if (value != null && !StringUtils.isEmpty(unit)) {
                    value = value + " " + definition.get(Constants.UNIT);
                }
            }
        }
    }
}